package com.bsoft.ecommerce.service;
import brave.Tracer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
 * @program: e-commerce-springclound
 * @description:
 * @author: hdh
 * @create: 2022:06:24 09:59
 */
//使用代码更直观的 sleuth 生成的跟踪信息
@Slf4j
@Service
public class SleuthTraceInfoService {
    private final Tracer tracer  ;
    public SleuthTraceInfoService(Tracer tracer) {
        this.tracer = tracer;
    }
    //打印当前的跟踪信息到日志中
    public  void  logCurrentTranceInfo(){
        log.info("Sleuth trance id [[]]",tracer.currentSpan().context().traceId());
        log.info("Sleuth span id [{}]" +tracer.currentSpan().context().spanId());
    }
}
